package com.wn.service.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yellow Docter
 * @date 2022 -09-01
 * @desc
 */
@Configuration
public class RabbitConfig {

    public static final String QUEUE_NAME = "Q3";
    public static final String EXCHANGE_NAME = "exchange_q3";
    public static final String ROUTINGKEY = "hello.q3";

    //队列
    @Bean("queue")
    public Queue queue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    //交换机
    @Bean("exchange")
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).build();
    }

    //交换机和路由绑定
    @Bean("bind")
    public Binding binding(@Qualifier("queue") Queue queue,@Qualifier("exchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY).noargs();
    }

}
